package com.ruoyi.device.controller;

import java.util.List;
import java.io.IOException;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.device.domain.TbArea;
import com.ruoyi.device.service.ITbAreaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 校区管理Controller
 * 
 * @author li
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/area")
@Tag(name = "校区管理", description = "校区管理相关操作API")
public class TbAreaController extends BaseController
{
    @Autowired
    private ITbAreaService tbAreaService;

    /**
     * 查询校区管理列表
     */
    @Operation(summary = "查询校区管理列表", description = "查询校区管理列表")
    @RequiresPermissions("ruoyi-device:area:list")
    @GetMapping("/list")
    public TableDataInfo list(TbArea tbArea)
    {
        startPage();
        List<TbArea> list = tbAreaService.selectTbAreaList(tbArea);
        return getDataTable(list);
    }

    /**
     * 导出校区管理列表
     */
    @Operation(summary = "导出校区管理列表", description = "导出校区管理列表")
    @RequiresPermissions("ruoyi-device:area:export")
    @Log(title = "校区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbArea tbArea)
    {
        List<TbArea> list = tbAreaService.selectTbAreaList(tbArea);
        ExcelUtil<TbArea> util = new ExcelUtil<TbArea>(TbArea.class);
        util.exportExcel(response, list, "校区管理数据");
    }

    /**
     * 获取校区管理详细信息
     */
    @Operation(summary = "获取校区管理详细信息", description = "获取校区管理详细信息")
    @RequiresPermissions("ruoyi-device:area:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbAreaService.selectTbAreaById(id));
    }

    /**
     * 新增校区管理
     */
    @Operation(summary = "新增校区管理", description = "新增校区管理")
    @RequiresPermissions("ruoyi-device:area:add")
    @Log(title = "校区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbArea tbArea)
    {
        return toAjax(tbAreaService.insertTbArea(tbArea));
    }

    /**
     * 修改校区管理
     */
    @Operation(summary = "修改校区管理", description = "修改校区管理")
    @RequiresPermissions("ruoyi-device:area:edit")
    @Log(title = "校区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbArea tbArea)
    {
        return toAjax(tbAreaService.updateTbArea(tbArea));
    }

    /**
     * 删除校区管理
     */
    @Operation(summary = "删除校区管理", description = "删除校区管理")
    @RequiresPermissions("ruoyi-device:area:remove")
    @Log(title = "校区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbAreaService.deleteTbAreaByIds(ids));
    }
}
